﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;

namespace WindowsFormsApplication3
{
    class JobCodeTransaction
    {
        //myintialization
          private String connString = Program.ConnStr;
        public JobCodeDataBean jobcodedatabean = null;

        private int jobpk1 = 0;

        public int getjobpkbyjobcode(String jobcode)
        {


            try
            {


                OleDbConnection oledbconnnection = new OleDbConnection(connString);
                oledbconnnection.Open();
                String query = "Select * from jobmastertable  Where jobcode='" + jobcode + "'";
                OleDbCommand oledbcomand = new OleDbCommand(query, oledbconnnection);
                OleDbDataReader reader = oledbcomand.ExecuteReader();
                if (reader.Read())
                {
                    jobpk1 = reader.GetInt32(0);

                }

                else
                {
                    jobpk1 = 1000;
                }

                reader.Close();
                oledbconnnection.Close();
            }
            catch (Exception exp)
            {
                Console.WriteLine("Error at Database in getjobpkbyjobcode" + exp);

            }
            finally
            {

            }

            return jobpk1;
        }



        public JobCodeDataBean getjobdatabeanbyjobpk(int jobpk)
        {
            jobcodedatabean = null;

            try
            {



                OleDbConnection oledbconnnection = new OleDbConnection(connString);
                oledbconnnection.Open();

                String query = "Select * from jobmastertable  Where jobpk=" + jobpk + "";
                OleDbCommand oledbcomand = new OleDbCommand(query, oledbconnnection);
                OleDbDataReader reader = oledbcomand.ExecuteReader();
                if (reader.Read())
                {


                    jobcodedatabean = new JobCodeDataBean();
                    jobcodedatabean.Jobpk = reader.GetInt32(0);
                    jobcodedatabean.Jobcode = reader.GetString(1);


                    jobcodedatabean.CompanyName1 = reader.GetString(2);
                    jobcodedatabean.Vehicleno1 = reader.GetString(3);
                    jobcodedatabean.Totaltrip = reader.GetInt32(4);
                    jobcodedatabean.Shipmenentdate = reader.GetDateTime(5);
                    jobcodedatabean.Triprent = reader.GetInt32(6);
                    jobcodedatabean.Sillabordercharges = reader.GetInt32(7);
                    jobcodedatabean.Battabordercharges = reader.GetInt32(8);
                    jobcodedatabean.Dutycharges = reader.GetInt32(9);
                    jobcodedatabean.Gatepass = reader.GetInt32(10);
                    jobcodedatabean.Retentioncharges = reader.GetInt32(11);
                    jobcodedatabean.Commision = reader.GetInt32(12);
                    jobcodedatabean.Advance = reader.GetInt32(13);

                    jobcodedatabean.Totalamount1 = reader.GetInt32(14);
                    jobcodedatabean.Drivername = reader.GetString(15);
                    jobcodedatabean.Vehicletype = reader.GetString(16);
                    jobcodedatabean.Fromplace = reader.GetString(17);
                    jobcodedatabean.Destination = reader.GetString(18);
                    if (jobcodedatabean != null)
                    {


                    }


                }



                reader.Close();
                oledbconnnection.Close();
            }
            catch (Exception exp)
            {
                Console.WriteLine("Error at Database in getjobpkbyjobcode" + exp);

            }
            finally
            {

            }

            return jobcodedatabean;
        }
        

    }
}
